const app = getApp();
var utils = require('../../untils/util.js');
Page({
  data: {
   marriageList:[] ,
    objectMarriageList:[] ,
    marriages:' ',

    sexList:[],
    objectSexList:[],
    sexs:' ',

    educationList: [],
    objeducationList:[] ,
    educations:' ',

     inComeList:[] ,
    objectInComeList:[] ,
    incomes:' ',

    ageList_1: [20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45],
    ageList_2: [20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45],

    age_1:'',
    age_2:'',

    cityList:[],
    objectCityList:[],
    citys:'',

    areaList:[],
    objectAreaList:[],
    areas:'',
    
    reqData:{
      id: '',
      pageno: 1,
      pagesize: 10,
      'xgmember.marry': '',
      'xgmember.money':'' ,
      'xgmember.sex': '',
      'xgmate.ageBegin': '',
      'xgmate.ageEnd': '',
      'xgmate.code':'' ,
      'xgmember.education':'' ,
      code: wx.getStorageSync('addCode'),
    }
  },
  onLoad: function () {
    this.initPage();
  },
  initPage: function () {
    var _this = this;
    app.doReq(app.globalData.DICTIONARY, {
      parentId: '340,8,418,2,6'//职业,婚姻状态,学历,月薪范围,省份
    }, 'get', function (res) {
      var data = res.data;
      console.log(data);
      if (data.code == 200) {
        var marriageList = data.obj[6];
        var marriageListTemp = [];
        for (let i of marriageList) {
          marriageListTemp.push(i.name);
        }

        var sexList = data.obj[340];
        var sexListTemp = [];
        for (let i of sexList) {
          sexListTemp.push(i.name);
        }

        var educationList = data.obj[8];
        var educationListTemp = [];
        for (let i of educationList) {
          educationListTemp.push(i.name);
        }

        var incomeList = data.obj[418];
        var incomeListTemp = [];
        for (let i of incomeList) {
          incomeListTemp.push(i.name);
        }
    
      
        _this.setData({
          inComeList: incomeListTemp,
          objectInComeList: incomeList,
          educationList: educationListTemp,
          objeducationList: educationList,
          marriageList: marriageListTemp,
          objectMarriageList: marriageList,
          sexList: sexListTemp,
          objectSexList: sexList,
        })
      }
    });

    app.doReq(app.globalData.SERVICE.MATES.ADDR,{
      parentId:2
    },'get',function(res){
   
      console.log(res);
        var data=res.data;
        if(data.code==200){
          var cityList=data.obj[2];
          var cityListTemp=[];
          for (let i of cityList) {
            cityListTemp.push(i.name);
          }

          _this.setData({
            cityList: cityListTemp,
            objectCityList: cityList,
          })
        }
    });
  },
  whenChange: function (e) { 
    var _this=this;
    var nodeType = e.currentTarget.dataset.type;
    var v = e.detail.value;//数组
    if (nodeType =="hunyin"){
      this.setData({
        marriages: _this.data.objectMarriageList[v].name,   
      })
      this.data.reqData['xgmember.marry'] = _this.data.objectMarriageList[v].id;
    } else if (nodeType =='xingbie'){
      this.setData({
        sexs: _this.data.objectSexList[v].name
      })
      this.data.reqData['xgmember.sex'] = _this.data.objectSexList[v].id;
    } else if (nodeType == 'nianji') {
      this.setData({
        age_1: _this.data.ageList_1[v],
      })
      this.data.reqData['xgmate.ageBegin'] = _this.data.ageList_1[v];
    } else if (nodeType == 'fanwei') {
      this.setData({
        age_2: _this.data.ageList_2[v],
      })
      this.data.reqData['xgmate.ageEnd'] = _this.data.ageList_2[v];
    } else if (nodeType == 'wenhua') {
      this.setData({
        educations: _this.data.objeducationList[v].name,
      })
      this.data.reqData['xgmember.education'] = _this.data.objeducationList[v].id;
    } else if (nodeType == 'shouru') {
      this.setData({
        incomes: _this.data.objectInComeList[v].name,
      })
      this.data.reqData['xgmember.money'] = _this.data.objectInComeList[v].id;
    }  else if (nodeType == 'dizhi') {
      this.setData({
        areas: _this.data.objectAreaList[v].name,
      })
      this.data.reqData['xgmate.code'] = _this.data.objectCityList[v].id;
    } 
  },
  whenCityChange: function (e) {
    var _this=this;
    var v = e.detail.value;
    this.setData({
      citys: _this.data.objectCityList[v].name,
    })
    var cityCode = _this.data.objectCityList[v].id;
    app.doReq(app.globalData.SERVICE.MATES.ADDR , { parentId:cityCode}, 'get',function (res) {
      let data = res.data;
      if (data.code == 200) {
        let areaList = data.obj[cityCode];
        let areaListTemp = [];
        for (let i of areaList) {
          areaListTemp.push(i.name);
        }
        _this.setData({
          areaList:  areaListTemp,
          objectAreaList: areaList
        })
      }
    });
  },
  doSave: function (e) {
    var _this=this;
    var req= _this.data.reqData;
    req.id=app.globalData.userid;
    app.doReq(app.globalData.SERVICE.MATES.LIST, req, 'get',
        function (res) {
          var data=res.data
            var pages = getCurrentPages();
              var currentPage = pages[pages.length - 1];//当前页面
              var pervPagge = pages[pages.length - 2];//上个页面
          if(data.code==200){
              if (pervPagge.data.pageno == 1) {
                pervPagge.setData({
                  renderObj:{
                    listArr: data.pageitems,
                  },
                  pageCount: data.pagecount,
                  reloadFlag: true
                })
              } else {
                pervPagge.setData({
                  renderObj: {
                    listArr: _pervPagge.data.renderObj.listArr.concat(data.pageitems)
                  },
                  pageCount: data.pagecount,
                  reloadFlag: true
                })
              }
              wx.navigateBack({});
          }
        });
  },
  doCancel: function () {
    wx.navigateBack({})
  }
})
